using UnityEngine;
using System.Collections;

[System.Serializable]
public class PlaySoundOnTrigger : MonoBehaviour {
	
	public AudioClip sound;
	public AudioSource source;
	public int playCount = 1;
	public bool playRandom = false;
	public int randomMin = 0;
	public int randomMax = 3;
	public int randomHitValue = 2;
	public float volume = 1;
	
	int played = 0;
	
	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter() {
		if (played < playCount) {
			System.Random rnd = new System.Random();
			int play = rnd.Next(randomMin, randomMax);
			if (!playRandom || ((playRandom && play == randomHitValue))) {
				source.PlayOneShot(sound);
				played++;
			}
		}
	}
}
